using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.ComponentModel;

namespace Axe.Web.Controls
{
    public class StatusLabel : CompositeControl
    {
        Image img = new Image();
        Literal literal = new Literal();

        #region public string StatusImageUrl
        [UrlProperty]
        [DefaultValue("")]
        [Bindable(true, BindingDirection.TwoWay)]
        public string StatusImageUrl
        {
            get
            {
                object o = ViewState["StatusImageUrl"];
                if (o == null)
                    return String.Empty;

                return (string)o;
            }
            set
            {
                ViewState["StatusImageUrl"] = value;
            }
        } 
        #endregion

        #region public string Text
        [Bindable(true)]
        [DefaultValue("")]
        [Localizable(true)]
        public string Text
        {
            get
            {
                object o = ViewState["Text"];
                if (o == null)
                    return String.Empty;

                return (string)o;
            }
            set
            {
                ViewState["Text"] = value;
            }
        } 
        #endregion

        protected virtual void CreateControlHierarchy()
        {
            img.ImageUrl = StatusImageUrl;
            literal.Text = Text;
            literal.Mode = LiteralMode.PassThrough;

            Table t = new Table();

            t.CopyBaseAttributes(this);
            t.ControlStyle.CopyFrom(this.ControlStyle);
            this.ControlStyle.Reset();

            TableRow row = new TableRow();

            TableCell imgCell = new TableCell();
            imgCell.Style.Add("vertical-align", "top");

            TableCell textCell = new TableCell();
            textCell.Style.Add("vertical-align", "top");

            imgCell.Controls.Add(img);
            textCell.Controls.Add(literal);

            row.Cells.Add(imgCell);
            row.Cells.Add(textCell);

            t.Rows.Add(row);

            Controls.Clear();
            Controls.Add(t);
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            CreateControlHierarchy();
        }
    }
}
